package com.ge.healthcare.autosc.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.ge.healthcare.autosc.dao.intf.CfgProDiagsScheduleDAO;
import com.ge.healthcare.autosc.dto.ScheduleBean;
import com.ge.healthcare.autosc.model.CfgProDiagsSchedule;

public class CfgProDiagsScheduleDAOImpl implements CfgProDiagsScheduleDAO {
	
	private final Logger logger = Logger.getLogger(CfgProDiagsScheduleDAOImpl.class);
	
	@Autowired
	private HibernateTemplate hibernateTemplate;
	
	protected Class<CfgProDiagsSchedule> getDataClass() {
		return CfgProDiagsSchedule.class;
	}
	
	
	@Override
	public void updateSchedule(CfgProDiagsSchedule cfgProDiagsSchedule) {
		hibernateTemplate.saveOrUpdate(cfgProDiagsSchedule);
	}
	
	public List<CfgProDiagsSchedule> getRequestBySystemID(String systemId) {
		DetachedCriteria dc = DetachedCriteria.forClass(getDataClass());
		List<CfgProDiagsSchedule> actRequestBean = new ArrayList<CfgProDiagsSchedule>();
					dc.add(Restrictions.eq("systemId", systemId));
			
			actRequestBean = (List<CfgProDiagsSchedule>)hibernateTemplate.findByCriteria(dc);
			System.out.println(actRequestBean.size());
		
		return actRequestBean;
	}
	
	public List<CfgProDiagsSchedule> getRequestByModelType(String modelType){
		DetachedCriteria dc = DetachedCriteria.forClass(getDataClass());
		List<CfgProDiagsSchedule> actRequestBean = new ArrayList<CfgProDiagsSchedule>();
					dc.add(Restrictions.eq("modelType", modelType));
			
			actRequestBean = (List<CfgProDiagsSchedule>)hibernateTemplate.findByCriteria(dc);
			System.out.println(actRequestBean.size());
		
		return actRequestBean;
	}
	@Override
	public List<CfgProDiagsSchedule> getAllObjects(ScheduleBean searchBean) {
		DetachedCriteria dc = DetachedCriteria.forClass(getDataClass());
		if(searchBean.getRequestId() != null){
			if(StringUtils.equals(searchBean.getRequestId(), "requestid")){
				dc.add(Restrictions.eq("systemId", searchBean.getTypeValue()));
			} 
		}
		return (List<CfgProDiagsSchedule>)hibernateTemplate.findByCriteria(dc);
	}
}
